﻿using System;
using System.Collections.Generic;
using Color = System.Drawing.Color;
using SwinGame;

namespace Gundam_2._0_Alpha.src
{
    public class Touhou1 : CharDrawAction
    {
        private List<Circles> circle = new List<Circles>();
        private Timer durationTimer = Core.CreateTimer();
        private int activate, duration, minDamage;
        private bool damageOn = false, isPlayer;

        public Touhou1(Character c, bool persistant, int row, int colEnd, int count, int lockoutLevel, int minDamage,
            int centerX, int centerY, int setCount, int activate, int duration, bool isPlayer)
            : base(c, persistant, row, colEnd, count, lockoutLevel)
        {
            this.minDamage = minDamage;
            this.isPlayer = isPlayer;
            this.activate = activate;
            this.duration = duration;
            float degrees = 0;
            float degreesInc = 0.07f;
            int health = 50000;
            bool isRandom = false;  // random positioning
            int nextSet = 8;    // circle objects per full circle
            float radius = 200.0f;
            for (int i = 0; i < setCount*8; i++)
            {
                if (i > nextSet)
                {
                    isRandom = true;
                    nextSet += 8;
                    centerX = Core.Rnd(GlobalConst.ScreenWidth);
                    centerY = Core.Rnd(GlobalConst.ScreenHeight);
                    radius = (float)(Core.Rnd(500) + 200);
                }
                Sprite circleSprite = Sprites.CreateSprite(Resources.LoadBitmap("touhou1.png"), 5, 6, 120, 60);
                GlobalConst.Utils.ActivateAnimationRow(circleSprite, 0, 2, 10);
                Circles tempCircle = new Circles("Touhou 1",circleSprite,health, radius, degrees, degreesInc, centerX, centerY, true,isRandom, c, isPlayer);
                tempCircle.IsActive = true;
                circle.Add(tempCircle);
                degrees += 0.79f;
            }
        }

        public override void DoAction(GameController gc)
        {
            if (Core.TimerTicks(durationTimer) == 0 && !IsActive)
            {
                IsActive = true;
                Core.StartTimer(durationTimer);
            }

            if (Core.TimerTicks(durationTimer) > activate && IsActive && !damageOn)
            {
                foreach (Circles ci in circle)
                    GlobalConst.Utils.ActivateAnimationRow(ci.ObjectSprite, 1, 2, 10);
                damageOn = true;
            }

            foreach (Circles ci in circle)
            {
                ci.Update(gc);
                ci.Damage = (int)((float)(Core.Rnd(minDamage)+minDamage) * c.StatModifier.DamageMultiplier);
            }

            if (Core.TimerTicks(durationTimer) > duration)
                Reset(gc);
            
        }

        public override void Draw()
        {
            foreach (Circles ci in circle)
                ci.Draw();
        }

        public override void Reset(GameController gc)
        {
            IsActive = false;
            c.LockoutTiers[LockoutLevel] = false;
            c.GlobalLockout = false;
            damageOn = false;
            Core.StopTimer(durationTimer);
            foreach (Circles ci in circle)
                GlobalConst.Utils.ActivateAnimationRow(ci.ObjectSprite, 0, 2, 10);
        }
    }
}
